<template>
  <div>
    <div class="his-hot" v-if="isShow">
      <div class="hd">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="delClick" />
      </div>
      <div class="bd">
        <van-tag
          plain
          type="default"
          v-for="(item, index) in historyKeywordList"
          :key="index"
          @click="tagClick(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>
    <div class="his-hot">
      <div class="hd">
        <h4>热门搜索</h4>
      </div>
      <div class="bd">
        <van-tag
          plain
          :type="item.is_hot == 1 ? 'danger' : 'default'"
          v-for="(item, index) in hotKeywordList"
          :key="index"
          @click="hotTagClick(item.keyword)"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHistory } from "@/request/api";

export default {
  props: ["historyKeywordList", "hotKeywordList"],
  data() {
    return { isShow: true };
  },
  methods: {
    tagClick(value) {
      this.$emit("tagClick", value);
    },
    hotTagClick(value) {
      this.$emit("hotTagClick", value);
    },
    delClick() {
      ClearHistory().then((res) =>
        setTimeout(() => {
          this.$toast.success("删除成功");
          this.isShow = false;
        }, 5000)
      );
    },
  },
};
</script>
 
<style lang = "less" scoped>
.his-hot {
  background-color: #fff;
  padding: 0.1rem 0.1rem 0;
  margin-bottom: 0.2rem;
  font-size: 0.186667rem;
  .hd {
    display: flex;
    justify-content: space-between;
    font-size: 0.18rem;
    margin-bottom: 0.1rem;
    h4 {
      font-size: 0.18rem;
    }
  }
  .van-tag {
    margin-right: 0.1rem;
    padding: 0 0.04rem;
    margin-bottom: 0.1rem;
  }
}
</style>